package demo2;

import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2023-05-19
 * Time: 10:11
 */
class Money implements Cloneable{
    public double money = 12.5;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Student implements Cloneable{
    public String name;
    public Money m = new Money();

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //只是克隆了student对象
        Student student = (Student) super.clone();
        //克隆了Student对象 里面的Money对象
        student.m = (Money) this.m.clone();
        return student;
    }

/*    public boolean equals(Object obj){
        if(obj == null){
            return false;
        }
        if(this == obj){
            return true;
        }
        if(! (obj instanceof Student)){
            return false;
        }
        Student student = (Student) obj;
        if(this.name.equals(student.name)){
            return true;
        }
        return false;
    }*/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}
class Person{

}
class Animla{

}
class Dog{

}
public class Test {

    public static void main(String[] args) {
        Student student1 = new Student();
        student1.name = "zhangsan";

        Dog dog = new Dog();
        boolean flg = student1.equals(dog);
        System.out.println(flg);
        //Student student2 = student1;
/*        Student student2 = new Student();
        student2.name = "zhangsan";*/

        /*System.out.println(student1 == student2);
        boolean flg = student1.equals(student2);
        System.out.println("flg: "+flg);*/

    }

/*    public static void main3(String[] args) {
        //func(new Dog());
    }*/
/*    public static void main2(String[] args) throws CloneNotSupportedException {


        Student student2 = (Student) student1.clone();
        System.out.println(student1.m.money);
        System.out.println(student2.m.money);
        System.out.println("=========================");
        student2.m.money = 99;
        System.out.println(student1.m.money);
        System.out.println(student2.m.money);


        Object o = new Student();
        System.out.println(o);
    }*/
    public static void main1(String[] args) throws CloneNotSupportedException{
        Student student1 = new Student();
        student1.name = "lkx";
        Student student2 = (Student) student1.clone();
        System.out.println(student2);
    }
}
